package com.artPreter.service.impl;


import com.artPreter.mapper.ArtVideoMapper;
import com.artPreter.pojo.ArtVideo;
import com.artPreter.pojo.ArtVideo;
import com.artPreter.service.IArtVideoService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * <p>
 * 视频内容表 服务实现类
 * </p>
 *
 * @author jarvis
 * @since 2024-12-24
 */
@Service
public class ArtVideoServiceImpl extends ServiceImpl<ArtVideoMapper, ArtVideo> implements IArtVideoService {

    @Override
    public List<ArtVideo> getList(ArtVideo artVideo) {
        LambdaQueryWrapper<ArtVideo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ArtVideo::getStatus,1);
        List<ArtVideo> result= this.baseMapper.selectList(queryWrapper);
        return result;
    }

    @Override
    public IPage<ArtVideo> getPage(Integer currentPage, Integer size, ArtVideo artVideo) {
        IPage<ArtVideo> artVideoIPage = new Page<>(currentPage, size);
        LambdaQueryWrapper<ArtVideo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ArtVideo::getStatus,1);
        artVideoIPage = this.baseMapper.selectPage(artVideoIPage, queryWrapper);
        return artVideoIPage;
    }

    @Override
    public void add(ArtVideo artVideo) {
        artVideo.setStatus(1);
        // 生成UUID并设置到实体对象中
        String uuid = UUID.randomUUID().toString();
        artVideo.setVideoId(uuid);
        this.baseMapper.insert(artVideo);
    }

    @Override
    public void edit(ArtVideo artVideo) {
        this.baseMapper.updateById(artVideo);
    }

    @Override
    public void delete(ArtVideo artVideo) {
        artVideo.setStatus(0);
        this.baseMapper.updateById(artVideo);
    }
}
